package zgs;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo1 {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个类名:");
        String className = scan.nextLine();
        Class cls = Class.forName(className);

        String name = cls.getName(); //获取类的完全限定名
        System.out.println(name);

        name = cls.getSimpleName();//仅获取类名
        System.out.println(name);

        Package pack = cls.getPackage();
        System.out.println(pack.getName());//输出包名

        Method[] methods = cls.getMethods();
        System.out.println("共:"+methods.length+"个方法:");
        for (Method method : methods) {
            System.out.println(method.getName());//遍历方法名
        }

    }
}
